package com.lagou.edu.controller;

import com.lagou.edu.service.EmailFeignService;
import com.lagou.edu.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

/**
 * 该类用于模拟，我们要使用共享的那些配置信息做一些事情
 */
@RestController
@RequestMapping("/code")
@RefreshScope
public class CodeController {

    @Autowired
    private CodeService codeService;
    @Autowired
    private EmailFeignService feignService;

    @RequestMapping(value = "/createCode", method = RequestMethod.POST)
    public String createCode(@RequestParam("email") String email) {
        String code = codeService.createCode(email);
        feignService.sendCode(code, email);
        return "yes";
    }

    @RequestMapping(value = "/validate", method = RequestMethod.POST)
    public String validateCode(@RequestParam(value = "code") String code) {
        String msg = codeService.validateCode(code);
        return msg;
    }

}
